using PetShop.Web.Controls;
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Petshop.Backend.Data;
using PetShop.Web.Entities;

namespace PetShop.Web {
	public class OrderProcess : Page {

		protected StaticAddress statAddrBill;
		protected StaticAddress statAddrShip;
		protected Repeater cart;
		protected NavBar header;
		protected System.Web.UI.WebControls.Label lblOrderDate;
		protected System.Web.UI.WebControls.Label lblUserId;
		protected System.Web.UI.WebControls.Label lblOrderId;
		protected System.Web.UI.WebControls.Label lblCardType;
		protected System.Web.UI.WebControls.Label lblCardExpiration;
		protected System.Web.UI.WebControls.Label lblCardNumber;
		protected System.Web.UI.WebControls.Label lblOrderTotal;

		protected Order myOrder;

		private void InitializeComponent() {}

		override protected void OnLoad(EventArgs e) {

			ProcessFlow.CartController cartController = new ProcessFlow.CartController();

			Order newOrder = cartController.PurchaseCart();

			//Display the order info to the user
			lblOrderId.Text = newOrder.OrderId.ToString();
			lblOrderDate.Text = newOrder.OrderDate.ToLongDateString();
			lblUserId.Text = newOrder.UserId;
			lblCardType.Text = newOrder.CardType;
			lblCardNumber.Text = newOrder.CreditCard;
            lblCardExpiration.Text = newOrder.ExprDate;

            statAddrBill.address = new AddressInfo() { Address1 = newOrder.BillAddr1, Address2 = newOrder.BillAddr2, City = newOrder.BillCity, Country = newOrder.BillCountry, FirstName = newOrder.BillToFirstName, LastName = newOrder.BillToLastName, Phone = "", State = newOrder.BillState, Zip = newOrder.BillZip };
            statAddrShip.address = new AddressInfo() { Address1 = newOrder.ShipAddr1, Address2 = newOrder.ShipAddr2, City = newOrder.ShipCity, Country = newOrder.ShipCountry, FirstName = newOrder.ShipToFirstName, LastName = newOrder.ShipToLastName, Phone = "", State = newOrder.ShipState, Zip = newOrder.ShipZip };
			
			cart.DataSource = newOrder.LineItems;
			cart.DataBind();

			lblOrderTotal.Text = newOrder.TotalPrice.ToString("c");
		}
	}
}